package net.scribblemedia.sqldsk.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import org.springframework.roo.addon.entity.RooEntity;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.tostring.RooToString;

@RooJavaBean
@RooToString
@RooEntity(finders = { "findDatabaseConfigsByDatabaseConfigNameEquals" })
public class DatabaseConfig {

    private String databaseConfigName;

    private String host;

    private String port;

    private String databaseName;

    @ManyToOne
    private DatabaseDriver driver;

    private String username;

    private String password;
    
    private boolean enabled;

    @OneToMany(cascade = { CascadeType.ALL }, mappedBy = "databaseConfig")
    private List<ReportQuery> reportQueries;

    public void addReportQuery(ReportQuery reportQuery) {
        if (reportQueries == null) {
            reportQueries = new ArrayList<ReportQuery>();
        }
        reportQueries.add(reportQuery);
        reportQuery.setDatabaseConfig(this);
    }
}
